Skip to content

Update type hints for linear search functions#14657

Open
dvanhu wants to merge 2 commits into
TheAlgorithms:masterfrom
dvanhu:add-type-hints-linear-search
Open

Update type hints for linear search functions#14657
dvanhu wants to merge 2 commits into
TheAlgorithms:masterfrom
dvanhu:add-type-hints-linear-search

Conversation

@dvanhu
Copy link
Copy Markdown

@dvanhu dvanhu commented May 8, 2026

  • I have read CONTRIBUTING.md
  • This pull request is all my own work
  • I know why this pull request was created

Fixes #14592

Changes Made

  • Added missing type hints to linear_search
  • Added missing type hints to rec_linear_search
  • Improved type clarity and readability
  • Preserved existing functionality

Reason

This improves maintainability and aligns the implementation with modern Python typing practices.

@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels May 8, 2026
Copy link
Copy Markdown

@mauricio812 mauricio812 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disculpen, soy nuevo en GitHub y me equivoqué de lugar al subir mi código. Ignoren mi actividad aquí, voy a crear mi propio repositorio."

Copy link
Copy Markdown

@mauricio812 mauricio812 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please of new repository

Copy link
Copy Markdown

@TTAAAN TTAAAN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function target parameter was explicitly set to int. It's good that the sequence is now set to list[int]. However, inside the documentation, it said "comparable items" and "item value to search". This could be misleading for the user since the algorithm explicitly expect only int value.

I think in this situation, you could either update the documentation too or update the algorithm parameters to a generic type. I suggest updating it to a generic one since the documentation already implies it should work on more types.

    :param sequence: a collection with comparable items (sorting is not required for
        linear search)
    :param target: item value to search

Edit: I reviewed a similar PR #14615 (review) . After thinking through it more, I believe Sequence[T] is the right approach here. Please check the review to see more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add missing type hints to functions in searches/linear_search.py

4 participants